﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using System.Windows.Threading;
using System.Windows.Media.Animation;


namespace clock
{

    public partial class WindowOrologio : Window
    {
        System.Timers.Timer timer = new System.Timers.Timer(1000);
        DispatcherTimer timercron = new DispatcherTimer();

        public WindowOrologio()
        {
            InitializeComponent();
            DateTime date = DateTime.Now;
            TimeZone time = TimeZone.CurrentTimeZone;
            TimeSpan difference = time.GetUtcOffset(date);
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
            timer.Enabled = true;
            timercron.Interval = TimeSpan.FromMilliseconds(10);
            timercron.Tick += new EventHandler(timertick);
            timercron.Start();
        }

        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
            {
                secondHand.Angle = DateTime.Now.Second * 6;
                minuteHand.Angle = DateTime.Now.Minute * 6;
                hourHand.Angle = (DateTime.Now.Hour * 30) + (DateTime.Now.Minute * 0.5);
                christianityCalendar.Content = DateTime.Today;
            }));
        }

        private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (this.Topmost == true)
            {
                this.Topmost = false;
            }
            else
            {
                this.Topmost = true;
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void ChiudiOrologio(object sender, EventArgs args)
        {
            this.Close();
        }

        private void Chiudi_Click(object sender, RoutedEventArgs e)
        {
            this.Hide();
        }

        private void timertick(object sender, EventArgs args)
        {
            if (AleCronoWPF.WinCronometro.labcrono != "00:00:00")
            {
                this.lblCrono.Visibility = Visibility.Visible;
                this.lblCrono.Foreground = Brushes.White;
                this.lblCrono.Content = AleCronoWPF.WinCronometro.labcrono;
            }
            else if (AleCronoWPF.WinCronometro.StartTimeCD != 0)
            {
                this.lblCrono.Visibility = Visibility.Visible;
                this.lblCrono.Foreground = Brushes.OrangeRed;
                this.lblCrono.Content = Convert.ToString(AleCronoWPF.WinCronometro.StartTimeCD);
                this.lblCrono.HorizontalAlignment = HorizontalAlignment.Center;
            }
            else
            {
                this.lblCrono.Visibility = Visibility.Hidden;
                this.lblCrono.Foreground = Brushes.White;
            }
        }
    }
}
